const handlerList = require("../containers/HandlerManager")
const HTTP_METHODS = require("../constant/httpMethod")
const routes = require("../containers/HandlerManager").handlerList

const RequestMappingHandler = (path) => {
  return (proto, key, desc) => {
    const isClassAnno = typeof proto === "function"
    if (isClassAnno) {
      const classRoutes = routes.filter(item => item.ctor === proto)
      classRoutes.forEach(item => item.path = path + item.path)
    } else {
      routes.push(...HTTP_METHODS.map(method => ({
        path: path,
        handler: proto[key],
        ctor: proto.constructor,
        method
      })))
    }
  }
}




module.exports = RequestMappingHandler
